package myapp.helper;

public class ConvertVietNamChar {

	private static String[] VietNamChar = new String[]
			{
				"aaeeoouuiiddyy",
				"ăâàảãạáằẳẵặắầẩẫậấ",
				"ĂÂÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤ",
				"êèẻẽẹéềểễệế",
				"ÊÈẺẼẸÉỀỂỄỆẾ",
				"ôơòỏõọóồổỗộốờởỡợớ",
				"ÔƠÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚ",
				"ưùủũụúừửữựứ",
				"ƯÙỦŨỤÚỪỬỮỰỨ",
				"ìỉĩịí",
				"ÌỈĨỊÍ",
				"đ",
				"Đ",
				"ỳỷỹỵý",
				"ỲỶỸỴÝ"				
			};
	
	
	public static String LocDau(String str) {

		for (int t = 0; t < str.length(); t++)
			if (Character.codePointAt(str, t) == 768		//Dấu huyền
			|| Character.codePointAt(str, t) == 769					//Dấu sắc
			|| Character.codePointAt(str, t) == 777					//Dấu hỏi
			|| Character.codePointAt(str, t) == 771					//Dấu ngã
			|| Character.codePointAt(str, t) == 803)				//Dấu nặng
				str = str.substring(0, t) +  str.substring(t+1, str.length());
		for (int i = 1; i <  VietNamChar.length; i++)
		{
			for (int j = 0; j < VietNamChar[i].length(); j++)
				str = str.replace(VietNamChar[i].charAt(j), VietNamChar[0].charAt(i-1));
		}	
		

		return str;
	}
}
